import { post } from '../util/proxy'

export function getAllpartmentsAll(header, callback) {
    var url = header.host + '/partment/getAllpartments'
    var data = JSON.stringify({
        "token": header.token,
    });
    post(url, data, callback);
}
export function getPartmentsApi(upPartmentId, header, callback) {

    $.ajax({
        url: header.host + '/partment/getPartments',
        type: "post",
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        async: true,
        data: JSON.stringify({
            "token": header.token,
            "upPartmentId": upPartmentId
        }),
        success: function(data) {
            // console.log(JSON.stringify(data, null, 2))
            if (data.code == 200) {
                callback.success(data.data)
            } else {
                callback.fail(data.msg)
            }
        },
        error: function(xhr, errorType, error) {
            //   console.log("网络错误")
            callback.fail("网络错误")
        }
    });
}
export function updatePartmentApi(upPartmentId, name, reviewUserIds, needCheck, partmentId, header, callback) {

    $.ajax({
        url: header.host + '/partment/updatePartment',
        type: "post",
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        async: true,
        data: JSON.stringify({
            "token": header.token,
            "upPartmentId": upPartmentId,
            "name": name,
            "reviewUserIds": reviewUserIds,
            "needCheck": needCheck,
            "partmentId": partmentId,
        }),
        success: function(data) {
            // console.log(JSON.stringify(data, null, 2))
            if (data.code == 200) {
                callback.success(data.data)
            } else {
                callback.fail(data.msg)
            }
        },
        error: function(xhr, errorType, error) {
            //   console.log("网络错误")
            callback.fail("网络错误")
        }
    });
}
export function addPartmentApi(upPartmentId, name, reviewUserIds, needCheck, header, callback) {

    $.ajax({
        url: header.host + '/partment/addPartment',
        type: "post",
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        async: true,
        data: JSON.stringify({
            "token": header.token,
            "upPartmentId": upPartmentId,
            "name": name,
            "reviewUserIds": reviewUserIds,
            "needCheck": needCheck,
        }),
        success: function(data) {
            // console.log(JSON.stringify(data, null, 2))
            if (data.code == 200) {
                callback.success(data.data)
            } else {
                callback.fail(data.msg)
            }
        },
        error: function(xhr, errorType, error) {
            //   console.log("网络错误")
            callback.fail("网络错误")
        }
    });
}
export function delPartmentApi(partmentId, header, callback) {

    $.ajax({
        url: header.host + '/partment/delPartment',
        type: "post",
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        async: true,
        data: JSON.stringify({
            "token": header.token,
            "partmentId": partmentId
        }),
        success: function(data) {
            // console.log(JSON.stringify(data, null, 2))
            if (data.code == 200) {
                callback.success(data.data)
            } else {
                callback.fail(data.msg)
            }
        },
        error: function(xhr, errorType, error) {
            //   console.log("网络错误")
            callback.fail("网络错误")
        }
    });
}